package com.yanqu.road.server.logic.recharge.limit.activity;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.mall.LimitBuyResult;
import com.yanqu.road.server.gameplayer.module.activity.festivalgift.FestivalGiftModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.utils.property.Property;

public class FestivalGiftActivityMallLimit extends BaseActivityMallLimit {

    public FestivalGiftActivityMallLimit(long userId, MallInfo mallInfo, ActivityInfo activityInfo) {
        super(userId, mallInfo, activityInfo);
    }

    @Override
    protected int activityCheck() {
        if(!ActivityMgr.activityInTime(activityInfo)){
            return GameErrorCode.E_ACTIVITY_NO_IN_TIME_CANNOT_BUY;
        }
        if(activityInfo.getType() != eActivityType.FestivalGift.getValue()){
            return GameErrorCode.E_ACTIVITY_NO_IN_TIME_CANNOT_BUY;
        }
        return 0;
    }

    @Override
    protected boolean isSystemUnLock() {
        return true;
    }

    @Override
    protected LimitBuyResult buyCountLimit() {
        return activityMallCountLimit(player);
    }

    @Override
    protected int logicCheck() {
        //判断是否选择了自选道具
        String[] extendParamArr = mallInfo.getExtendParam().split("\\|");
        if (extendParamArr.length > 4) {
            // 自选
            Property property = player.getModule(FestivalGiftModule.class).getSelectedProperty(mallInfo.getActivityId(), mallInfo.getMallId());
            if (property == null || property.getGoods().isEmpty()) {
                return GameErrorCode.E_SELF_SELECT_GIFT_NOT_SELECT_ENOUGH;
            }
        } else {
            // 非自选
        }
        return 0;
    }
}